export const PAYMENT_METHOD_SERVICE = {
  PAYPAL: 'PAYPAL',
  STRIPE: 'STRIPE',
  OPENCOLLECTIVE: 'OPENCOLLECTIVE',
  THEGIVINGBLOCK: 'THEGIVINGBLOCK',
  WISE: 'WISE',
  PREPAID: 'PREPAID', // Should this be here? (it's in the GQL types)
};

export const EXPENSE_PAYMENT_METHOD_SERVICES = [PAYMENT_METHOD_SERVICE.PAYPAL, PAYMENT_METHOD_SERVICE.WISE];

export const PAYMENT_METHOD_TYPE = {
  ALIPAY: 'ALIPAY',
  CREDITCARD: 'CREDITCARD',
  PREPAID: 'PREPAID',
  PAYMENT: 'PAYMENT',
  SUBSCRIPTION: 'SUBSCRIPTION',
  COLLECTIVE: 'COLLECTIVE',
  HOST: 'HOST',
  ADAPTIVE: 'ADAPTIVE',
  GIFTCARD: 'GIFTCARD',
  MANUAL: 'MANUAL',
  CRYPTO: 'CRYPTO',
  PAYMENT_INTENT: 'PAYMENT_INTENT',
  US_BANK_ACCOUNT: 'US_BANK_ACCOUNT',
  SEPA_DEBIT: 'SEPA_DEBIT',
  BACS_DEBIT: 'BACS_DEBIT',
  BANCONTACT: 'BANCONTACT',
};

export const GQLV2_PAYMENT_METHOD_LEGACY_TYPES = {
  ACCOUNT_BALANCE: 'ACCOUNT_BALANCE',
  ALIPAY: 'ALIPAY',
  BANK_TRANSFER: 'BANK_TRANSFER',
  CREDIT_CARD: 'CREDIT_CARD',
  CRYPTO: 'CRYPTO',
  GIFT_CARD: 'GIFT_CARD',
  PAYPAL: 'PAYPAL',
  PREPAID_BUDGET: 'PREPAID_BUDGET',
};

export const GQLV2_SUPPORTED_PAYMENT_METHOD_TYPES = {
  ALIPAY: GQLV2_PAYMENT_METHOD_LEGACY_TYPES.ALIPAY,
  BANK_TRANSFER: GQLV2_PAYMENT_METHOD_LEGACY_TYPES.BANK_TRANSFER,
  CREDIT_CARD: GQLV2_PAYMENT_METHOD_LEGACY_TYPES.CREDIT_CARD,
  PAYPAL: GQLV2_PAYMENT_METHOD_LEGACY_TYPES.PAYPAL,
  PAYMENT_INTENT: PAYMENT_METHOD_TYPE.PAYMENT_INTENT,
};

const matchPm = (pm, service, type) => {
  return pm && pm.service === service && pm.type === type;
};

/** Returns true if the given payment method is a prepaid */
export const isPrepaid = pm => {
  return matchPm(pm, PAYMENT_METHOD_SERVICE.OPENCOLLECTIVE, PAYMENT_METHOD_TYPE.PREPAID);
};

/** Returns payment methods with recurring payment support **/
export const ProvidersWithRecurringPaymentSupport = [
  GQLV2_PAYMENT_METHOD_LEGACY_TYPES.CREDIT_CARD,
  GQLV2_PAYMENT_METHOD_LEGACY_TYPES.PAYPAL,
  GQLV2_PAYMENT_METHOD_LEGACY_TYPES.ACCOUNT_BALANCE,
];
